package net.gazhi.delonix.rbac.web.controller;

import javax.validation.Valid;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

import net.gazhi.delonix.core.annonation.ApiAction;
import net.gazhi.delonix.core.annonation.ApiController;
import net.gazhi.delonix.core.annonation.ApiLevel;
import net.gazhi.delonix.core.web.AbstractAnnotationController;
import net.gazhi.delonix.rbac.form.GroupEditForm;
import net.gazhi.delonix.rbac.service.GroupService;

@Controller
@RequestMapping("/rbac/group")
@ApiController("群组模块")
public class GroupController extends AbstractAnnotationController {

	@Autowired
	private GroupService groupService;

	@ApiAction(name = "保存分组", level = ApiLevel.GROUP_ADMIN)
	@RequestMapping(value = "/save", method = RequestMethod.POST)
	public ModelAndView save(@RequestBody @Valid GroupEditForm form, BindingResult result) {
		groupService.get(1);
		return super.resultView(result);
	}
	
	@ApiAction(name = "移动分组", level = ApiLevel.GROUP_ADMIN)
	@RequestMapping(value = "/move", method = RequestMethod.GET)
	public ModelAndView move(int id, int prentId, BindingResult result) {
		groupService.get(1);
		return super.resultView(result);
	}

	@ApiAction(name = "删除分组", level = ApiLevel.GROUP_ADMIN)
	@RequestMapping(value = "/del", method = RequestMethod.GET)
	public ModelAndView del(int id, BindingResult result) {
		groupService.get(1);
		return super.resultView(result);
	}

}
